from PySide6.QtWidgets import (QWidget, QVBoxLayout, QListWidgetItem,
                               QLabel)
from PySide6.QtCore import Qt

from .draggable_list import DraggableListWidget


class LibraryPanel(QWidget):
    def __init__(self, apsParser):
        super().__init__()
        self.apsParser = apsParser
        self.initUI()

    def initUI(self):
        layout = QVBoxLayout(self)
        layout.addWidget(QLabel("音频处理模块"))

        # 使用可拖拽的列表控件
        self.moduleList = DraggableListWidget()

        subSystems = self.apsParser.getAllSubSystems()

        for systemType, systemData in subSystems.items():
            item = QListWidgetItem(systemData.get('name', systemType))
            item.setData(Qt.UserRole, systemType)

            # 设置工具提示显示更多信息
            tooltip = f"类型: {systemType}\n"
            tooltip += f"输入: {', '.join(systemData.get('inputs', []))}\n"
            tooltip += f"输出: {', '.join(systemData.get('outputs', []))}\n"
            tooltip += f"描述: {systemData.get('equation', '无描述')}"
            item.setToolTip(tooltip)

            self.moduleList.addItem(item)

        layout.addWidget(self.moduleList)